package com.hyts.scanner.facade;

import com.hyts.scanner.base.AbstractScanner;
import com.hyts.scanner.bean.ScanBaseObject;
import com.hyts.scanner.core.SourceAndJarHandler;

import java.util.List;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.scanner.facade
 * author:Libo/Alex
 * create-date:2019-05-13 21:57
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: ScannerBuilder构建器
 */
public class ScannerBuilder {


    ScanBaseObject scanBaseObject;


    AbstractScanner abstractScanner;


    public static ScannerBuilder create(){
        return new ScannerBuilder();
    }

    void build(){
        scanBaseObject = new ScanBaseObject();
    }

    public ScannerBuilder excludePackage(String... excludePackage){
        if(scanBaseObject == null){
            build();
        }
        scanBaseObject.excludePackages = excludePackage;
        return this;
    }

    public ScannerBuilder includePackage(String... includePackage){
        if(scanBaseObject == null){
            build();
        }
        scanBaseObject.packages = includePackage;
        return this;
    }

    public ScannerBuilder annotation(Class<?>... annotations){
        if(scanBaseObject == null){
            build();
        }
        scanBaseObject.annotations = annotations;
        return this;
    }

    public List<Class<?>> scanToClass(boolean recursive){
        if(scanBaseObject == null){
            build();
        }
        abstractScanner = new SourceAndJarHandler(recursive);
        return abstractScanner.scan(scanBaseObject).scanResultClass;
    }

    public List<Class<?>> scanToClass(){
        if(scanBaseObject == null){
            build();
        }
        abstractScanner = new SourceAndJarHandler(true);
        return abstractScanner.scan(scanBaseObject).scanResultClass;
    }

    public List<String> scanToFile(boolean recursive){
        if(scanBaseObject == null){
            build();
        }
        abstractScanner = new SourceAndJarHandler(recursive);
        return abstractScanner.scan(scanBaseObject).scanResultFile;
    }

    public List<String> scanToFile(){
        if(scanBaseObject == null){
            build();
        }
        abstractScanner = new SourceAndJarHandler(true);
        return abstractScanner.scan(scanBaseObject).scanResultFile;
    }

}
